home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 236 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  52 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: b91926@fnclub.fnal.gov (David Sachs)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Explicit constructor call vs Temporaries
  5. Date: 1 Feb 1996 22:54:37 GMT
  6. Organization: Fermi National Accelerator Laboratory, Batavia IL
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Distribution: usa
  9. Message-ID: <4er2vu$jk5@fnnews.fnal.gov>
  10. References: <4e6plv$idn@eclipse.eng.sc.rolm.com>
  11. Reply-To: sachs@fnal.fnal.gov
  12. NNTP-Posting-Host: taumet.eng.sun.com
  13. Content-Type: text
  14. X-Nntp-Posting-Host: fnclub.fnal.gov
  15. Content-Length: 833
  16. X-Lines: 28
  17. Originator: clamage@taumet
  18.  
  19. eddy@siemensrolm.com (eddy Gorsuch) writes:
  20.  
  21. >Is an explicit call to an object constructor (an unamed object) const or
  22. >not? I have code like the following where I don't care about the parameter
  23. >to X::f(), so I just created an unamed T(). I thought I had tried to compile
  24. >this code and got errors about trying to pass a const object to a non const
  25. >reference parameter. Thinking that the unamed T() counts as a temporary (and
  26. >therefor const) object, I believed that the compiler was right. Now somebody
  27. >tells me that the following code is legal. Is it?
  28.  
  29. >class T {
  30. >  T();
  31. >  ~T();
  32. >}
  33.  
  34. >class X {
  35. >  X();
  36. >  ~X();
  37. >  f(T& t);
  38. >}
  39.  
  40. >int main() {
  41. >  X x;
  42. >  x.f(T());  // Compiler complained on this line
  43. >}
  44.  
  45. Doesn't the statement violate the rule that a temporary may not be
  46. used for a non-const reference parameter of a function?
  47.  
  48. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  49.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  50.   summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  51. ]
  52.